/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { createContext, RefObject } from 'react';
import type { PanGestureHandlerProps, State } from 'react-native-gesture-handler';
import type { AnimateToPositionType, AdaptiveSheetProps } from '../components/adaptiveSheet/types';
import type { ANIMATION_STATE, SCROLLABLE_STATE, SCROLLABLE_TYPE, SHEET_STATE } from '../constants';
import type { Scrollable, ScrollableRef } from '../types';
import { SharedValue } from 'react-native-reanimated';

export interface AdaptiveSheetInternalContextType
  extends Pick<PanGestureHandlerProps, 'activeOffsetY' | 'activeOffsetX' | 'failOffsetY' | 'failOffsetX' | 'waitFor' | 'simultaneousHandlers'>,
    Required<
      Pick<AdaptiveSheetProps, 'enableContentPanningGesture' | 'enableOverDrag' | 'enablePanDownToClose' | 'enableDynamicSizing' | 'overDragResistanceFactor'>
    > {
  // animated states
  animatedAnimationState: SharedValue<ANIMATION_STATE>;
  animatedSheetState: SharedValue<SHEET_STATE>;
  animatedScrollableState: SharedValue<SCROLLABLE_STATE>;
  animatedContentGestureState: SharedValue<State>;
  animatedHandleGestureState: SharedValue<State>;

  // animated values
  animatedSnapPoints: SharedValue<number[]>;
  animatedPosition: SharedValue<number>;
  animatedIndex: SharedValue<number>;
  animatedContainerHeight: SharedValue<number>;
  animatedContentHeight: SharedValue<number>;
  animatedHighestSnapPoint: SharedValue<number>;
  animatedClosedPosition: SharedValue<number>;
  animatedFooterHeight: SharedValue<number>;
  animatedHandleHeight: SharedValue<number>;
  animatedScrollableType: SharedValue<SCROLLABLE_TYPE>;
  animatedScrollableContentOffsetY: SharedValue<number>;
  animatedScrollableOverrideState: SharedValue<SCROLLABLE_STATE>;
  isScrollableRefreshable: SharedValue<boolean>;
  isContentHeightFixed: SharedValue<boolean>;
  isInTemporaryPosition: SharedValue<boolean>;

  // methods
  stopAnimation: () => void;
  animateToPosition: AnimateToPositionType;
  setScrollableRef: (ref: ScrollableRef) => void;
  removeScrollableRef: (ref: RefObject<Scrollable>) => void;
}

export const AdaptiveSheetInternalContext = createContext<AdaptiveSheetInternalContextType | null>(null);

export const AdaptiveSheetInternalProvider = AdaptiveSheetInternalContext.Provider;
